/*
 *
 * 目录
 */

import { createAPI } from '@/utils/request'
// 引入moment
import moment from 'moment'

// 目录列表
export const list = data => createAPI('/directorys', 'get', data)
.then(res => ({
  items: res.data.items.map((d, i) => ({
    ...d,
    index: i + 1,
    state: d.state === 1 ? '已启用' : '已禁用',
    addDate: moment(d.addDate).format('YYYY-MM-DD HH:mm:ss'),
  })),
  counts: res.data.counts
}))
.catch(err => err)

// 目录简单列表
export const catalogueslist = () => createAPI('/directorys/simple', 'get')
.then(res => res.data)
.catch(() => ({}))


// 目录详情
export const detail = data => createAPI(`/directorys/${data.id}`, 'get', data)

// 目录添加
export const add = data => createAPI('/directorys', 'post', data)
.then(res => res)
.catch(err => err)

// 目录修改
export const update = data => createAPI(`/directorys/${data.id}`, 'put', data)

// 目录删除
export const remove = data => createAPI(`/directorys/${data.id}`, 'delete', data)
.then(res =>res)
.catch(err => err)

// 目录状态
export const changeState = data => createAPI(`/directorys/${data.id}/${data.state}`, 'post', data)
